import os
import tensorflow as tf

if __name__ == '__main__':
    os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
    # 创建一个张量
    dataset = tf.reshape(tf.range(15), shape=(5, 3))
    print(dataset)

    # from_tensor_slices()
    # The given tensors are sliced along their first dimension.
    # 给定的张量按照第一个维度(最高维度)进行切片——按照存储方式——按行存储

    result_dataset1 = tf.data.Dataset.from_tensor_slices(dataset)
    print(result_dataset1)

    # print(list(result_dataset))
    for data in result_dataset1:
        print(data)

    # 三层，四行，五列
    result_dataset2 = tf.data.Dataset.from_tensor_slices(tf.reshape(tf.range(60), shape=(3, 4, 5)))
    # for data in result_dataset2:
    #     print(data)

    iterator = result_dataset2.as_numpy_iterator()
    print(list(iterator))

    # from_tensors()
    result_dataset3 = tf.data.Dataset.from_tensors(dataset)
    print(result_dataset3)

    print(list(result_dataset3))
